<template>
  <mt-select
    v-bind="$attrs"
    :options="options"
    v-on="$listeners">
  </mt-select>
</template>

<script>
import Dictionary from "@/class/Dictionary";
export default {
  name: "MtDictionary",

  props: {
    dict: { type: String, default: "" }, // 字典名称，参考字典管理模块传参
    onlyShow: { type: Boolean, default: false } // 只读模式
  },

  data () {
    return {
      options: []
    };
  },

  computed: {
    dictionary() {
      return this.DICT || {};
    }
  },

  created () {
    if (this.dict) {
      const storeDict = this.dictionary.list[this.dict];
      if (!storeDict) this.getDict();
      else this.options = storeDict;

      if (this.onlyShow) {
        this.options.forEach(i => {
          i.disabled = true;
        });
      }
    }
  },

  mounted () {},

  methods: {
    getDict () {
      this.dictionary.setDictByApi(this.dict);
      setTimeout(() => {
        this.options = this.dictionary.list[this.dict];
      }, 500);
    }
  }
};
</script>

<style lang="scss" scoped>
</style>
